package main

import (
	"encoding/json"
	"fmt"

	"github.com/shopspring/decimal"
)

type DataWrap struct {
	Page int         `json:"page"`
	Code int         `json:"code"`
	Data []*DataItem `json:"data"`
}

type DataItem struct {
	Name string `json:"name"`
	Num  int    `json:"num"`
}

//解析json
type DecodeJson struct {
	Data DecodeData
}

type DecodeData struct {
	Data DecodeDataItem `json:"data"`
}

type DecodeDataItem struct {
	Symbol string          `json:"symbol"`
	Column []string        `json:"column"`
	Item   [][]interface{} `json:"item"`
}

func main() {
	var dw = &DataWrap{Page: 1, Code: 0}
	dw.Data = append(dw.Data, &DataItem{"t1", 1}, &DataItem{"t2", 2})
	b, _ := json.Marshal(dw)
	fmt.Println(string(b))

	var jsonStr = `{"data":{"symbol":"SH600010","column":["timestamp","volume","open","high","low","close","chg","percent","turnoverrate","amount","volume_post","amount_post","pe","pb","ps","pcf","market_capital","balance","hold_volume_cn","hold_ratio_cn","net_volume_cn","hold_volume_hk","hold_ratio_hk","net_volume_hk"],"item":[[1626278400000,3083836220,2.08,2.3,1.99,2.25,0.16,7.66,9.74,6.60137138E9,null,null,70.0487,1.9117,1.6138,15.7664,1.02566323458E11,2.761333674E9,889476982,2.8,80760379,null,null,null],[1626364800000,2260138773,2.18,2.27,2.12,2.15,-0.1,-4.44,7.13,4.963746153E9,null,null,66.9354,1.8268,1.542,15.0657,9.80078201932E10,null,null,null,null,null,null,null]]},"error_code":0,"error_description":""}`

	jsonStrByte := []byte(jsonStr)
	decodeData := DecodeData{}
	json.Unmarshal(jsonStrByte, &decodeData)

	for _, v := range decodeData.Data.Item {
		//1.6262784e+12 科学计数转换为字符串
		str := fmt.Sprintf("%v", v[0])
		fmt.Println(str)
		decimalNum, err := decimal.NewFromString(str)
		if err != nil {
			fmt.Println(err)
			return
		}
		fmt.Println(decimalNum)
	}
}
